#include "tools.h"
#include"utils.h"

Tools::Tools()
{
}


 void Tools::Antivirals(Building *building)
{
    for(int i = building->CurrentPeopleAccessor().count() - 1; i >= 0; i--)
    {
        if(building->CurrentPeopleAccessor().at(i)->virus != 0)
            building->CurrentPeopleAccessor().at(i)->virus->Hp -= rand() % 500;
    }
}

 void Tools::Gammaglobulins(Building *building)
{
    for(int i = building->CurrentPeopleAccessor().count() - 1; i >= 0; i--)
    {
        double increasor = (double)(rand() % 10);
        increasor /= 100;
        increasor = Utils::clampF(increasor, 0.3, 2.5);
        building->CurrentPeopleAccessor().at(i)->stats->resistenceSetter(building->CurrentPeopleAccessor().at(i)->stats->resistenceGetter() + increasor);
    }
}

 void Tools::Sterilization(Building *building)
{
    for(int i = building->CurrentPeopleAccessor().count() - 1; i >= 0; i--)
    {
        building->SterilitySetter(building->SterilityGetter() + 1);
    }
}

 void Tools::CleanWater(QList<Building *> buildings)
 {
     for (int index = 0; index < buildings.length(); index++)
     {
         Sterilization(buildings.at(index));
         Sterilization(buildings.at(index));
     }
 }

 void Tools::Vaccene(Building *building)
{
    for(int i = building->CurrentPeopleAccessor().count() - 1; i >= 0; i--)
    {
        int random = rand() % 1000;
        if(random >= 980)
        {
            //Allergic reaction
            building->CurrentPeopleAccessor().at(i)->stats->hpSetter(building->CurrentPeopleAccessor().at(i)->stats->hpGetter() - rand() % 300);
        }
        else if(random >= 800)
        {
            //Gives them the virus
            if(building->CurrentPeopleAccessor().at(i)->virus == 0)
            {

            }
            //Strengthens an existing one
            else
            {
                building->CurrentPeopleAccessor().at(i)->virus->Hp = building->CurrentPeopleAccessor().at(i)->virus->StartingHp;
            }
        }
        else if(random >= 500)
        {
            //nothing happens!
        }
        else
        {
            //Immunity
             building->CurrentPeopleAccessor().at(i)->stats->resistenceSetter(0.3);
        }
    }
}

 void Tools::GeneTherapy(Building *building)
 {
     for(int i = building->CurrentPeopleAccessor().count() - 1; i >= 0; i--)
     {
        building->CurrentPeopleAccessor().at(i)->stats->resistenceSetter(0.3);
     }
 }



